Add @introduceDomain event-watch and replace consoled watch on /console.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 5 Sep 2005 19:43:04 +0000 (19:43 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 5 Sep 2005 19:43:04 +0000 (19:43 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/console/daemon/io.c
tools/console/daemon/utils.c
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_core.h
tools/xenstore/xenstored_domain.c
tools/xenstore/xenstored_watch.c

index 885e2914564c92f501229cf36767d73534cfafec..39956dccdf455c79ae46ef64e4c1bf69d922a9d6 100644 (file)
@@ -212,12 +212,10 @@ int xs_gather(struct xs_handle *xs, const char *dir, ...)
 
 static int domain_create_ring(struct domain *dom)
 {
-       char *dompath, *path;
+       char *dompath;
        int err;
 
-       asprintf(&path, "/console/%d/domain", dom->domid);
-       dompath = xs_read(xs, path, NULL);
-       free(path);
+       dompath = xs_get_domain_path(xs, dom->domid);
        if (!dompath)
                return ENOENT;
 
@@ -452,6 +450,7 @@ static void handle_xs(int fd)
                if (dom && (dom->evtchn_fd == -1 || dom->page == NULL))
                        domain_create_ring(dom);
        }
+       enum_domains();
 
        xs_acknowledge_watch(xs, vec[1]);
        free(vec);
index e29fc11ead5f607bba5d9ff8cb76e9a5181df616..3e0400c6d143c3929e30697504d48ad65f25ce30 100644 (file)
@@ -233,8 +233,8 @@ bool xen_setup(void)
                goto out_close_data;
        }
 
-       if (!xs_watch(xs, "/console", "console")) {
-               dolog(LOG_ERR, "xenstore watch on /console fails.");
+       if (!xs_watch(xs, "@introduceDomain", "console")) {
+               dolog(LOG_ERR, "xenstore watch on @introduceDomain fails.");
                goto out_close_data;
        }
 
index 4aef491ce17cdf5cbf79bd225219f6bd94406427..3c7e6cc12de935eab7a4bd7a04fdab6eb758d5ea 100644 (file)
@@ -828,6 +828,15 @@ bool check_node_perms(struct connection *conn, const char *node,
        return false;
 }
 
+bool check_event_node(const char *node)
+{
+       if (!node || !strstarts(node, "@")) {
+               errno = EINVAL;
+               return false;
+       }
+       return true;
+}
+
 static void send_directory(struct connection *conn, const char *node)
 {
        char *path, *reply;
index ce0f8fc792a88391ddfdbce6b796b1668c5d5658..fa407e9ae1edcb155503826911d5dde2fb28a5d3 100644 (file)
@@ -133,6 +133,9 @@ char *canonicalize(struct connection *conn, const char *node);
 bool check_node_perms(struct connection *conn, const char *node,
                      enum xs_perm_type perm);
 
+/* Check if node is an event node. */
+bool check_event_node(const char *node);
+
 /* Path to this node outside transaction. */
 char *node_dir_outside_transaction(const char *node);
 
index e98a347a857dae6fbc7235c5f309b7be9dfa8201..2d6528105ee9da80f9c478887afc1714856fc858 100644 (file)
@@ -33,6 +33,7 @@
 #include "talloc.h"
 #include "xenstored_core.h"
 #include "xenstored_domain.h"
+#include "xenstored_watch.h"
 #include "xenstored_test.h"
 
 static int *xc_handle;
@@ -308,6 +309,9 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
 
        /* Now domain belongs to its connection. */
        talloc_steal(domain->conn, domain);
+
+       fire_watches(conn, "@introduceDomain", false);
+
        send_ack(conn, XS_INTRODUCE);
 }
 
index a2727e46e48eb5922a3686dd04bb7048ee9e05fc..804a386868e54e66cc3c13030e9745fca6fbd4d9 100644 (file)
@@ -103,7 +103,8 @@ static void add_event(struct connection *conn,
        /* Check read permission: no permission, no watch event.
         * If it doesn't exist, we need permission to read parent.
         */
-       if (!check_node_perms(conn, node, XS_PERM_READ|XS_PERM_ENOENT_OK)) {
+       if (!check_node_perms(conn, node, XS_PERM_READ|XS_PERM_ENOENT_OK) &&
+           !check_event_node(node)) {
                fprintf(stderr, "No permission for %s\n", node);
                return;
        }
@@ -213,11 +214,16 @@ void do_watch(struct connection *conn, struct buffered_data *in)
                return;
        }
 
-       relative = !strstarts(vec[0], "/");
-       vec[0] = canonicalize(conn, vec[0]);
-       if (!is_valid_nodename(vec[0])) {
-               send_error(conn, errno);
-               return;
+       if (strstarts(vec[0], "@")) {
+               relative = false;
+               /* check if valid event */
+       } else {
+               relative = !strstarts(vec[0], "/");
+               vec[0] = canonicalize(conn, vec[0]);
+               if (!is_valid_nodename(vec[0])) {
+                       send_error(conn, errno);
+                       return;
+               }
        }
 
        watch = talloc(conn, struct watch);